package com.cy.jxc.controller;


import com.cy.jxc.entity.User;
import com.cy.jxc.service.RegistService;
import com.cy.jxc.vo.JsonResult;
import com.cy.jxc.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("/register/")
public class RegisterController {
    @Autowired
    RegistService registService;
    @RequestMapping("sendmail")
    public JsonResult sendMail(@RequestParam("email") String email){
        System.out.println(email);
      String num= String.valueOf(new Random().nextInt(8999)+1000);
        System.out.println(num);
        registService.sendMail("1746575586@qq.com", email, "企业经销存系统邮箱","请保管好你的验证码："+num+",将在60秒后失效" );
        if (num!=null){
            registService.saveMailnum(num);
        }
        return  new JsonResult();
    }

    @RequestMapping("registerform")
    public JsonResult register(RegisterVo registerVo,@RequestParam("yzm") String yzm){
        System.out.println(registerVo);
        System.out.println(yzm);
        registService.register(registerVo, yzm);
        return new  JsonResult("恭喜，您的账号注册成功");
    }




}
